﻿#include "Dialog_SetThermostat.h"
#include "ui_Dialog_SetThermostat.h"

#include "DeviceInfoManager.h"
#include "Device.h"

Dialog_SetThermostat::Dialog_SetThermostat(QWidget *parent) :
  QDialog(parent),
  ui(new Ui::Dialog_SetThermostat)
{
  ui->setupUi(this);
  setFixedSize(size());
  connect(ui->pushButton_confirm,&QPushButton::clicked,this,&Dialog_SetThermostat::accept);
  connect(ui->pushButton_cancel,&QPushButton::clicked,this,&Dialog_SetThermostat::reject);
  lineEdit_ThermostatRate=ui->lineEdit_temperatureRate;
  lineEdit_ThermostatTemperature=ui->lineEdit_targetTemperature;
}

Dialog_SetThermostat::~Dialog_SetThermostat()
{
  delete ui;
}

float Dialog_SetThermostat::getTemperature()
{
  return lineEdit_ThermostatTemperature->getTemperature();
}

float Dialog_SetThermostat::getRate()
{
  return lineEdit_ThermostatRate->getRate();
}

int Dialog_SetThermostat::exec()
{
  slot_updateThermostatInfo();
  return QDialog::exec();
}

void Dialog_SetThermostat::accept()
{
  QDialog::accept();
}

void Dialog_SetThermostat::reject()
{
  slot_updateThermostatInfo();
  QDialog::reject();
}

void Dialog_SetThermostat::slot_updateThermostatInfo()
{
  Device* device=deviceInfoManager->getDeviceInfoByDeviceId(deviceId);
  if(Q_NULLPTR==device)
    {
      return;
    }
  lineEdit_ThermostatTemperature->setTemperature(device->getTurnTable_thermostat_targetTemperature());
  lineEdit_ThermostatRate->setRate(device->getTurnTable_thermostat_targetTemperatureRate());
}

uint Dialog_SetThermostat::getDeviceId()
{
  return deviceId;
}

Dialog_SetThermostat* Dialog_SetThermostat::setDeviceId(uint deviceId)
{
  this->deviceId=deviceId;
  return this;
}

DeviceInfoManager* Dialog_SetThermostat::getDeviceInfoManager()const
{
  return deviceInfoManager;
}

Dialog_SetThermostat* Dialog_SetThermostat::setDeviceInfoManager(DeviceInfoManager* const deviceInfoManager)
{
  this->deviceInfoManager=deviceInfoManager;
  printInjection(this,deviceInfoManager);
  return this;
}

void Dialog_SetThermostat::objectAutoInjection(QHash<QString,QObject*>* objMap)
{
  setDeviceInfoManager(getObjFromMap<DeviceInfoManager>(objMap));
}
